/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package layoutHandling;

import java.util.HashMap;

/**
 *
 * @author LittleHobbit
 */
public class LayoutHandler {

    private static LayoutHandler singleton;
    private HashMap<String, LayoutWeight> map = new HashMap<String, LayoutWeight>();
    private Integer layout1Score;
    private Integer layout2Score;
    private Integer layout3Score;
    private static final Integer LAYOUT1 = 1;
    private static final Integer LAYOUT2 = 2;
    private static final Integer LAYOUT3 = 3;

    private LayoutHandler() {
        map.put("aeh", new LayoutWeight());
        map.put("expert", new LayoutWeight());
        map.put("a_help", new LayoutWeight());
        map.put("aeh_approved", new LayoutWeight());
        map.put("gender_separation", new LayoutWeight());
        map.put("presence", new LayoutWeight());
        map.put("culture", new LayoutWeight());
        map.put("hierarchy", new LayoutWeight());
        map.put("l_help", new LayoutWeight());
        map.put("access", new LayoutWeight());
        map.put("choice", new LayoutWeight());
        map.put("ambiguity", new LayoutWeight());
        map.put("security", new LayoutWeight());
    }

    public static LayoutHandler getInstance() {
        if (singleton == null) {
            singleton = new LayoutHandler();
        }
        return singleton;
    }

    public void putValue(String name, String value) {
        if (map.containsKey(name)) {
            LayoutWeight lw = map.get(name);
            lw.setName(value);
        }
    }

    public void putWeight(String name, Integer weight) {
        if (map.containsKey(name)) {
            LayoutWeight lw = map.get(name);
            lw.setWeight(weight);
        }
    }

    public HashMap<String, LayoutWeight> getMap() {
        return map;
    }

    public void setMap(HashMap<String, LayoutWeight> map) {
        this.map = map;
    }

    public int matchLayout() {
        if (map.get("aeh").getName().equals("accept")) {
            layout1Score += map.get("aeh").getWeight();
        } else {
            layout2Score += map.get("aeh").getWeight();
            layout3Score += map.get("aeh").getWeight();
        }

        if (map.get("expert").getName().equals("peers")) {
            layout1Score += map.get("expert").getWeight();
        } else {
            layout2Score += map.get("expert").getWeight();
            layout3Score += map.get("expert").getWeight();
        }


        if (map.get("a_help").getName().equals("less")) {
            layout1Score += map.get("a_help").getWeight();
        } else {
            layout2Score += map.get("a_help").getWeight();
            layout3Score += map.get("a_help").getWeight();
        }

        if (map.get("aeh_approved").getName().equals("display")) {
            layout1Score += map.get("aeh_approved").getWeight();
        } else {
            layout2Score += map.get("aeh_approved").getWeight();
            layout3Score += map.get("aeh_approved").getWeight();
        }

        if (map.get("gender_separation").getName().equals("rejected")) {
            layout1Score += map.get("gender_separation").getWeight();
        }
        layout2Score += map.get("gender_separation").getWeight();
        layout3Score += map.get("gender_separation").getWeight();

        if (map.get("presence").getName().equals("hide")) {
            layout3Score += map.get("presence").getWeight();
        } else {
            layout1Score += map.get("presence").getWeight();
            layout2Score += map.get("presence").getWeight();
        }

        if (map.get("culture").getName().equals("hide")) {
            layout3Score += map.get("culture").getWeight();
        } else {
            layout1Score += map.get("culture").getWeight();
            layout2Score += map.get("culture").getWeight();
        }

        if (map.get("hierarchy").getName().equals("shallow")) {
            layout1Score += map.get("hierarchy").getWeight();
        } else {
            layout2Score += map.get("hierarchy").getWeight();
            layout3Score += map.get("hierarchy").getWeight();
        }

        if (map.get("l_help").getName().equals("more")) {
            layout2Score += map.get("l_help").getWeight();
        } else {
            layout1Score += map.get("l_help").getWeight();
            layout3Score += map.get("l_help").getWeight();
        }

        if (map.get("access").getName().equals("limited")) {
            layout2Score += map.get("access").getWeight();
        } else {
            layout1Score += map.get("access").getWeight();
            layout3Score += map.get("access").getWeight();
        }


        if (map.get("choice").getName().equals("open")) {
            layout3Score += map.get("choice").getWeight();
        } else {
            layout1Score += map.get("choice").getWeight();
            layout2Score += map.get("choice").getWeight();
        }

        if (map.get("ambiguity").getName().equals("less")) {
            layout2Score += map.get("ambiguity").getWeight();
        } else {
            layout1Score += map.get("ambiguity").getWeight();
            layout3Score += map.get("ambiguity").getWeight();
        }

        if (map.get("security").getName().equals("present")) {
            layout1Score += map.get("security").getWeight();
        } else {
            layout2Score += map.get("security").getWeight();
            layout3Score += map.get("security").getWeight();
        }

        if (layout1Score > layout2Score) {
            if (layout1Score > layout3Score) {
                return LAYOUT1;
            } else {
                return LAYOUT3;
            }
        } else {
            if (layout2Score > layout3Score) {
                return LAYOUT2;
            } else {
                return LAYOUT3;
            }
        }
    }
}
